﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using System.Text;
using DCI6;
using DCI6.Client.API;
using C2rChangeNotifier6_1112;
//using C2rChangeNotifier6_1314;
using DCI6.Client.Payloads1112.abcs;

//using DCI6.Client.Payloads1314.c2r;

namespace DCIAPIRMSampleCode {
    public class C2rChangesSampleCode {
        private Advertisement ad;
        private Item item;
        private Notifier n;
        private string configDDS;

        private void n_C2rChange(Object source, C2rChangeEvent c2rEvt) {
            Console.WriteLine("received C2R Change Event");

            C2rRoleType role = c2rEvt.role;
            if (role != null) {
                Console.WriteLine("...Role change");
                Console.WriteLine(role.Shortname);
                Console.WriteLine(role.Symbolcode);
                Console.WriteLine(role.Urn);
                Console.WriteLine("");
            }

            C2rUnitType unit = c2rEvt.unit;
            if (unit != null) {
                Console.WriteLine("...Unit change");
                Console.WriteLine(unit.Shortname);
                Console.WriteLine(unit.Symbolcode);
                Console.WriteLine(unit.Urn);
                Console.WriteLine("");
            }
        }


        public C2rChangesSampleCode(string ddsConfig) {
            configDDS = ddsConfig;
            n = new Notifier();
            n.C2rChange += new C2rChangeEventHandler(n_C2rChange);
        }


        public void tearDown() {
            ad.Unadvertise(configDDS);
        }


        public void testC2rChangeNotifier() {
            ad = new Advertisement()
                .ClearCategories()
                .ClearKeywords()
                .AddCategory("C2rChanges")
                .SetBounds(-90.0, -180.0, 90.0, 180.0)
                .Create2(configDDS);

            item = new Item();
            item.add(C2rChanges1112);

            Publication pub = new Publication(ad);
            pub.add(item);
            pub.publish(configDDS);

            Thread.Sleep(10000);
        }


        public const String C2rChanges1112 =
            "<ABCS:C2rChanges xmlns:ABCS=\"http://peoc3t.us.army.mil/abcs\">\n" +
            " <ABCS:C2rRoleChange>\n" +
            "  <ABCS:C2rRole>\n" +
            "   <ABCS:adconurn>1911416</ABCS:adconurn>\n" +
            "   <ABCS:opconurn>1911416</ABCS:opconurn>\n" +
            "   <ABCS:organicurn>1911416</ABCS:organicurn>\n" +
            "   <ABCS:systemname>AMPS</ABCS:systemname>\n" +
            "   <ABCS:ip>22.218.7.195</ABCS:ip>\n" +
            "   <ABCS:longname>AAMDWS-ADACP-MAIN-82AB</ABCS:longname>\n" +
            "   <ABCS:shortname>AAMDWS-ADACP-MAIN-82AB</ABCS:shortname>\n" +
            "   <ABCS:mail>AAMDWS-ADACP-MAIN-82AB@82AB.DS.ARMY.SMIL.MIL</ABCS:mail>\n" +
            "   <ABCS:mil47001version>C</ABCS:mil47001version>\n" +
            "   <ABCS:or_name>UNK~HHC82AB~~USAMDWSGROUPOPS~~~~~</ABCS:or_name>\n " +
            "   <ABCS:symbolcode>SFGPEVUX----USG</ABCS:symbolcode>\n" +
            "   <ABCS:urn>556419</ABCS:urn>\n" +
            "   <ABCS:usmtfbodybaseline>USMTF_2004</ABCS:usmtfbodybaseline>\n" +
            "   <ABCS:vmfbodybaseline>Software_Block_1</ABCS:vmfbodybaseline>\n" +
            "   <ABCS:afatdsunitid>AMDWS  ADACP  MAIN      82AB</ABCS:afatdsunitid>\n" +
            "   <ABCS:ssmtype>legacy</ABCS:ssmtype>\n" +
            "   <ABCS:modifytimestamp>2008-03-24T15:18:56.000Z</ABCS:modifytimestamp>\n" +
            "  </ABCS:C2rRole>\n" +
            "  <ABCS:C2rChangeOperation>update</ABCS:C2rChangeOperation>\n" +
            " </ABCS:C2rRoleChange>\n" +
            " <ABCS:C2rChangeDateTime>2008-03-24T15:18:56.937Z</ABCS:C2rChangeDateTime>\n" +
            "</ABCS:C2rChanges>";


        //public const String C2rChanges1314 =
        //  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        //  "<C2rChanges xmlns=\"http://peoc3t.us.army.mil/abcs/C2r:2.0\">" +
        //  "<Security p2:classification=\"U\" p2:ownerProducer=\"ownerProducer1 ownerProducer2 ownerProducer3 \" p2:SCIcontrols=\"SCIcontrols1 SCIcontrols2 SCIcontrols3 \" p2:SARIdentifier=\"SARIdentifier1 SARIdentifier2 SARIdentifier3 \" p2:disseminationControls=\"disseminationControls1 disseminationControls2 disseminationControls3 \" p2:FGIsourceOpen=\"FGIsourceOpen1 FGIsourceOpen2 FGIsourceOpen3 \" p2:FGIsourceProtected=\"FGIsourceProtected1 FGIsourceProtected2 FGIsourceProtected3 \" p2:releasableTo=\"releasableTo1 releasableTo2 releasableTo3 \" p2:nonICmarkings=\"nonICmarkings1 nonICmarkings2 nonICmarkings3 \" p2:classifiedBy=\"classifiedBy1\" p2:derivativelyClassifiedBy=\"derivativelyClassifiedBy1\" p2:classificationReason=\"classificationReason1\" p2:derivedFrom=\"derivedFrom1\" p2:declassDate=\"1900-01-01\" p2:declassEvent=\"declassEvent1\" p2:declassException=\"declassException1 declassException2 declassException3 \" p2:typeOfExemptedSource=\"typeOfExemptedSource1 typeOfExemptedSource2 typeOfExemptedSource3 \" p2:dateOfExemptedSource=\"1900-01-01\" p2:declassManualReview=\"true\" xmlns:p2=\"urn:us:gov:ic:ism:v2\" xmlns=\"http://peoc3t.us.army.mil/abcs/common:2.0\" />" +
        //  "<C2rUnitChange>" +
        //    "<C2rUnit>" +
        //      "<adconurn>16777215</adconurn>" +
        //      "<opconurn>16777215</opconurn>" +
        //      "<organicurn>16777215</organicurn>" +
        //      "<nationality>USA</nationality>" +
        //      "<domain>domain2</domain>" +
        //      "<department>ARM</department>" +
        //      "<longname>longname2</longname>" +
        //      "<shortname>shortname2</shortname>" +
        //      "<uic>A2</uic>" +
        //      "<symbolcode>SFGPU----------</symbolcode>" +
        //      "<urn>16777215</urn>" +
        //      "<modifytimestamp>0001-01-01T00:00:00-05:00</modifytimestamp>" +
        //    "</C2rUnit>" +
        //    "<C2rChangeOperation>update</C2rChangeOperation>" +
        //  "</C2rUnitChange>" +
        //  "</C2rChanges>";
    }
}